//
// Created by HP on 2025/11/5.
//

#include "../include/route.h"
#include <iostream>
#include <sstream>

void registerRoutes(Server &app) {
    // GET / - 首页
    app.get("/", [](const Request& /*req*/, Response& res) {
        res.json(R"({"message":"Welcome to Flight Server API"})");
    });

    // GET /api/health - 健康检查
    app.get("/api/health", [](const Request& /*req*/, Response& res) {
        res.json(R"({"status":"ok","message":"Server is running"})");
    });

    app.post("/api/v1/login", login);
    app.post("/api/v1/checkLogin", CheckLogin);

    app.put("/api/v1/sendVerifyCode", sendVerificationEmail);
    app.post("/api/v1/sendRegister", registerUser);
    // 查票api
    app.post("/api/v1/sendQueryOneWay", handlerQueryOneWay);
    app.post("/api/v1/sendQueryRoundTrip", handlerQueryRoundTrip);
    app.post("/api/v1/sendQueryTransfer", handlerQueryTransfer);
    app.post("/api/v1/sendQueryRefund", handlerQueryRefund);
    app.post("/api/v1/senderQueryPoint", handlerQueryCheckPoint);
    app.post("/api/v1/senderQueryOnSale", handlerQueryOnSale);


    // 管理员api
    app.get("/api/v1/dashboard/statistics", getDashBoardStatistics);
    app.get("/api/v1/tickets", getTickets);
    app.post("/api/v1/add/tickets", addTickets);
    app.put("/api/v1/tickets", updateTickets);
    app.del("/api/v1/tickets", deleteTickets);
    app.get("/api/v1/tickets/search", searchTickets);
    app.get("/api/v1/orders", getOrders);
    app.put("/api/v1/orders", updateOrders);
    app.del("/api/v1/orders", deleteOrders);
    app.get("/api/v1/orders/search", searchUsersOrders);
    app.get("/api/v1/orders/statistics", getOrdersStatistics);
    app.get("/api/v1/users", getUsers);
    app.get("/api/v1/users/search", searchUsers);
    app.get("/api/v1/users/statistics", getUsersStatistics);
    app.get("/api/v1/users/detail", getUsersDetail);
    app.post("/api/v1/users/freeze", freezeUser);
    app.post("/api/v1/users/unfreeze", unfreezeUser);
    app.get("/api/v1/statistics", getStatistics);
    app.get("/api/v1/statistics/details", getStatisticsDetails);
    app.get("/api/v1/statistics/charts/revenue", getRevenueChart);
    app.get("/api/v1/statistics/charts/category", getCategoryChart);

    app.get("/api/v1/income/statistics", getIncomeStatistics);
    app.get("/api/v1/income/source-analysis", getIncomeSourceAnalysis);
    app.get("/api/v1/income/trend-analysis", getIncomeTrend);

    app.get("/api/v1/game-contents", getGameContent);
    app.post("/api/v1/game-contents", addGameContent);
    app.del("/api/v1/game-contents", deleteGameContent);
    app.put("/api/v1/game-contents", updateGameContent);
    app.get("/api/v1/announcements", getAnnouncement);
    app.post("/api/v1/announcements", addAnnouncement);
    app.del("/api/v1/announcements", deleteAnnouncement);
    app.put("/api/v1/announcements", updateAnnouncement);

    app.post("/api/v1/addTicketsByTrain", addTicketsByTrain);

    app.get("/api/v1/accounts/paginated", getAccountsPaginated);
    app.post("/api/v1/accounts", addAccount);
    app.put("/api/v1/users", updateUser);
    app.del("/api/v1/users", deleteUser);
    app.get("/api/logs/pagination", getLogsPaginated);

    app.get("api/v1/adminType", getAdminType);

    // 共用api
    app.get("/api/v1/cities", getCities);
    app.get("/api/v1/stations", getStations);
    app.get("/api/v1/cities/cnt", getCitiesCnts);
    app.get("/api/v1/stations/cnt", getStationCnts);
}